<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="lib/vue.js"></script>
</head>
<body>
<div id="app">
    {{msg}}
    <br/>
    <input type="button" @click="myStart" value="开始">
    <input type="button" @click="myStop()" value="停止">
</div>

<script>
    new Vue({
        el: "#app",
        data: {
            msg: '这是跑马灯',
            intervalId: null
        },
        methods: {
            myStart() {
                if (this.intervalId == null) {
                    var _this = this;
                    this.intervalId = setInterval(() => {
                        _this.msg = _this.msg.substr(1, this.msg.length - 1) + _this.msg.substr(0, 1);
                    }, 300);
                }
            },
            myStop() {
                clearInterval(this.intervalId);
                this.intervalId = null;
            }
        }
    })
</script>

</body>
</html>
